<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="乘客手机号" prop="passengerPhone">
        <el-input
          v-model="queryParams.passengerPhone"
          placeholder="请输入乘客手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['car:info:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['car:info:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['car:info:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['car:info:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="订单ID" align="center" prop="id" />
      <el-table-column label="乘客ID" align="center" prop="passengerId" />
      <el-table-column label="乘客手机号" align="center" prop="passengerPhone" />
      <el-table-column label="司机ID" align="center" prop="driverId" />
      <el-table-column label="司机手机号" align="center" prop="driverPhone" />
      <el-table-column label="车辆Id" align="center" prop="carId" />
      <el-table-column label="车辆类型" align="center" prop="vehicleType" />
      <el-table-column label="发起地行政区划代码" align="center" prop="address" />
      <el-table-column label="订单发起时间" align="center" prop="orderTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.orderTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="预计用车时间" align="center" prop="departTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.departTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="预计出发地点详细地址" align="center" prop="departure" />
      <el-table-column label="预计出发地点经度" align="center" prop="depLongitude" />
      <el-table-column label="预计出发地点纬度" align="center" prop="depLatitude" />
      <el-table-column label="预计目的地" align="center" prop="destination" />
      <el-table-column label="预计目的地经度" align="center" prop="destLongitude" />
      <el-table-column label="预计目的地纬度" align="center" prop="destLatitude" />
      <el-table-column label="坐标加密标识
1:GCJ-02测绘局标准
2:WGS84 GPS标准
3:BD-09 百度标准
4:CGCS2000 北斗标准
0:其他" align="center" prop="encrypt" />
      <el-table-column label="运价类型编码" align="center" prop="fareType" />
      <el-table-column label="票价版本" align="center" prop="fareVersion" />
      <el-table-column label="接单时车辆经度" align="center" prop="receiveOrderCarLongitude" />
      <el-table-column label="接单时车辆纬度" align="center" prop="receiveOrderCarLatitude" />
      <el-table-column label="接单时间，派单成功时间" align="center" prop="receiveOrderTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.receiveOrderTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="机动车驾驶证号" align="center" prop="licenseId" />
      <el-table-column label="车辆号牌" align="center" prop="vehicleNo" />
      <el-table-column label="司机去接乘客出发时间" align="center" prop="toPickUpPassengerTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.toPickUpPassengerTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="去接乘客时，司机的经度" align="center" prop="toPickUpPassengerLongitude" />
      <el-table-column label="去接乘客时，司机的纬度" align="center" prop="toPickUpPassengerLatitude" />
      <el-table-column label="去接乘客时，司机的地点" align="center" prop="toPickUpPassengerAddress" />
      <el-table-column label="司机到达上车点时间" align="center" prop="driverArrivedDepartureTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.driverArrivedDepartureTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="接到乘客，乘客上车时间" align="center" prop="pickUpPassengerTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.pickUpPassengerTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="接到乘客，乘客上车经度" align="center" prop="pickUpPassengerLongitude" />
      <el-table-column label="接到乘客，乘客上车纬度" align="center" prop="pickUpPassengerLatitude" />
      <el-table-column label="乘客下车时间" align="center" prop="passengerGetoffTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.passengerGetoffTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="乘客下车经度" align="center" prop="passengerGetoffLongitude" />
      <el-table-column label="乘客下车纬度" align="center" prop="passengerGetoffLatitude" />
      <el-table-column label="订单撤销时间" align="center" prop="cancelTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.cancelTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="撤销发起者：1:乘客
2:驾驶员
3:平台公司" align="center" prop="cancelOperator" />
      <el-table-column label="撤销类型代码
1:乘客提前撤销
2:驾驶员提前撤销
3:平台公司撤销
4;乘客违约撤销
5:驾驶员违约撤销" align="center" prop="cancelTypeCode" />
      <el-table-column label="载客里程" align="center" prop="driveMile" />
      <el-table-column label="载客时间(分)" align="center" prop="driveTime" />
      <el-table-column label="订单状态1：订单开始 2：司机接单 3：去接乘客 4：司机到达乘客起点 5：乘客上车，司机开始行程 6：到达目的地，行程结束，未支付 7：发起收款 8: 支付完成 9.订单取消'" align="center" prop="orderStatus" />
      <el-table-column label="金额" align="center" prop="price" />
      <el-table-column label="创建时间" align="center" prop="gmtCreate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.gmtCreate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修改时间" align="center" prop="gmtModified" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.gmtModified, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['car:info:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['car:info:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改订单信息2对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="乘客ID" prop="passengerId">
          <el-input v-model="form.passengerId" placeholder="请输入乘客ID" />
        </el-form-item>
        <el-form-item label="乘客手机号" prop="passengerPhone">
          <el-input v-model="form.passengerPhone" placeholder="请输入乘客手机号" />
        </el-form-item>
        <el-form-item label="司机ID" prop="driverId">
          <el-input v-model="form.driverId" placeholder="请输入司机ID" />
        </el-form-item>
        <el-form-item label="司机手机号" prop="driverPhone">
          <el-input v-model="form.driverPhone" placeholder="请输入司机手机号" />
        </el-form-item>
        <el-form-item label="车辆Id" prop="carId">
          <el-input v-model="form.carId" placeholder="请输入车辆Id" />
        </el-form-item>
        <el-form-item label="发起地行政区划代码" prop="address">
          <el-input v-model="form.address" placeholder="请输入发起地行政区划代码" />
        </el-form-item>
        <el-form-item label="订单发起时间" prop="orderTime">
          <el-date-picker clearable
            v-model="form.orderTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择订单发起时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="预计用车时间" prop="departTime">
          <el-date-picker clearable
            v-model="form.departTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择预计用车时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="预计出发地点详细地址" prop="departure">
          <el-input v-model="form.departure" placeholder="请输入预计出发地点详细地址" />
        </el-form-item>
        <el-form-item label="预计出发地点经度" prop="depLongitude">
          <el-input v-model="form.depLongitude" placeholder="请输入预计出发地点经度" />
        </el-form-item>
        <el-form-item label="预计出发地点纬度" prop="depLatitude">
          <el-input v-model="form.depLatitude" placeholder="请输入预计出发地点纬度" />
        </el-form-item>
        <el-form-item label="预计目的地" prop="destination">
          <el-input v-model="form.destination" placeholder="请输入预计目的地" />
        </el-form-item>
        <el-form-item label="预计目的地经度" prop="destLongitude">
          <el-input v-model="form.destLongitude" placeholder="请输入预计目的地经度" />
        </el-form-item>
        <el-form-item label="预计目的地纬度" prop="destLatitude">
          <el-input v-model="form.destLatitude" placeholder="请输入预计目的地纬度" />
        </el-form-item>
        <el-form-item label="坐标加密标识
1:GCJ-02测绘局标准
2:WGS84 GPS标准
3:BD-09 百度标准
4:CGCS2000 北斗标准
0:其他" prop="encrypt">
          <el-input v-model="form.encrypt" placeholder="请输入坐标加密标识
1:GCJ-02测绘局标准
2:WGS84 GPS标准
3:BD-09 百度标准
4:CGCS2000 北斗标准
0:其他" />
        </el-form-item>
        <el-form-item label="票价版本" prop="fareVersion">
          <el-input v-model="form.fareVersion" placeholder="请输入票价版本" />
        </el-form-item>
        <el-form-item label="接单时车辆经度" prop="receiveOrderCarLongitude">
          <el-input v-model="form.receiveOrderCarLongitude" placeholder="请输入接单时车辆经度" />
        </el-form-item>
        <el-form-item label="接单时车辆纬度" prop="receiveOrderCarLatitude">
          <el-input v-model="form.receiveOrderCarLatitude" placeholder="请输入接单时车辆纬度" />
        </el-form-item>
        <el-form-item label="接单时间，派单成功时间" prop="receiveOrderTime">
          <el-date-picker clearable
            v-model="form.receiveOrderTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择接单时间，派单成功时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="机动车驾驶证号" prop="licenseId">
          <el-input v-model="form.licenseId" placeholder="请输入机动车驾驶证号" />
        </el-form-item>
        <el-form-item label="车辆号牌" prop="vehicleNo">
          <el-input v-model="form.vehicleNo" placeholder="请输入车辆号牌" />
        </el-form-item>
        <el-form-item label="司机去接乘客出发时间" prop="toPickUpPassengerTime">
          <el-date-picker clearable
            v-model="form.toPickUpPassengerTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择司机去接乘客出发时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="去接乘客时，司机的经度" prop="toPickUpPassengerLongitude">
          <el-input v-model="form.toPickUpPassengerLongitude" placeholder="请输入去接乘客时，司机的经度" />
        </el-form-item>
        <el-form-item label="去接乘客时，司机的纬度" prop="toPickUpPassengerLatitude">
          <el-input v-model="form.toPickUpPassengerLatitude" placeholder="请输入去接乘客时，司机的纬度" />
        </el-form-item>
        <el-form-item label="去接乘客时，司机的地点" prop="toPickUpPassengerAddress">
          <el-input v-model="form.toPickUpPassengerAddress" placeholder="请输入去接乘客时，司机的地点" />
        </el-form-item>
        <el-form-item label="司机到达上车点时间" prop="driverArrivedDepartureTime">
          <el-date-picker clearable
            v-model="form.driverArrivedDepartureTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择司机到达上车点时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="接到乘客，乘客上车时间" prop="pickUpPassengerTime">
          <el-date-picker clearable
            v-model="form.pickUpPassengerTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择接到乘客，乘客上车时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="接到乘客，乘客上车经度" prop="pickUpPassengerLongitude">
          <el-input v-model="form.pickUpPassengerLongitude" placeholder="请输入接到乘客，乘客上车经度" />
        </el-form-item>
        <el-form-item label="接到乘客，乘客上车纬度" prop="pickUpPassengerLatitude">
          <el-input v-model="form.pickUpPassengerLatitude" placeholder="请输入接到乘客，乘客上车纬度" />
        </el-form-item>
        <el-form-item label="乘客下车时间" prop="passengerGetoffTime">
          <el-date-picker clearable
            v-model="form.passengerGetoffTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择乘客下车时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="乘客下车经度" prop="passengerGetoffLongitude">
          <el-input v-model="form.passengerGetoffLongitude" placeholder="请输入乘客下车经度" />
        </el-form-item>
        <el-form-item label="乘客下车纬度" prop="passengerGetoffLatitude">
          <el-input v-model="form.passengerGetoffLatitude" placeholder="请输入乘客下车纬度" />
        </el-form-item>
        <el-form-item label="订单撤销时间" prop="cancelTime">
          <el-date-picker clearable
            v-model="form.cancelTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择订单撤销时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="撤销发起者：1:乘客
2:驾驶员
3:平台公司" prop="cancelOperator">
          <el-input v-model="form.cancelOperator" placeholder="请输入撤销发起者：1:乘客
2:驾驶员
3:平台公司" />
        </el-form-item>
        <el-form-item label="撤销类型代码
1:乘客提前撤销
2:驾驶员提前撤销
3:平台公司撤销
4;乘客违约撤销
5:驾驶员违约撤销" prop="cancelTypeCode">
          <el-input v-model="form.cancelTypeCode" placeholder="请输入撤销类型代码
1:乘客提前撤销
2:驾驶员提前撤销
3:平台公司撤销
4;乘客违约撤销
5:驾驶员违约撤销" />
        </el-form-item>
        <el-form-item label="载客里程" prop="driveMile">
          <el-input v-model="form.driveMile" placeholder="请输入载客里程" />
        </el-form-item>
        <el-form-item label="载客时间(分)" prop="driveTime">
          <el-input v-model="form.driveTime" placeholder="请输入载客时间(分)" />
        </el-form-item>
        <el-form-item label="金额" prop="price">
          <el-input v-model="form.price" placeholder="请输入金额" />
        </el-form-item>
        <el-form-item label="创建时间" prop="gmtCreate">
          <el-date-picker clearable
            v-model="form.gmtCreate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="修改时间" prop="gmtModified">
          <el-date-picker clearable
            v-model="form.gmtModified"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择修改时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInfo, getInfo, delInfo, addInfo, updateInfo } from "@/api/car/info";

export default {
  name: "Info",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单信息2表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        passengerPhone: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询订单信息2列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        passengerId: null,
        passengerPhone: null,
        driverId: null,
        driverPhone: null,
        carId: null,
        vehicleType: null,
        address: null,
        orderTime: null,
        departTime: null,
        departure: null,
        depLongitude: null,
        depLatitude: null,
        destination: null,
        destLongitude: null,
        destLatitude: null,
        encrypt: null,
        fareType: null,
        fareVersion: null,
        receiveOrderCarLongitude: null,
        receiveOrderCarLatitude: null,
        receiveOrderTime: null,
        licenseId: null,
        vehicleNo: null,
        toPickUpPassengerTime: null,
        toPickUpPassengerLongitude: null,
        toPickUpPassengerLatitude: null,
        toPickUpPassengerAddress: null,
        driverArrivedDepartureTime: null,
        pickUpPassengerTime: null,
        pickUpPassengerLongitude: null,
        pickUpPassengerLatitude: null,
        passengerGetoffTime: null,
        passengerGetoffLongitude: null,
        passengerGetoffLatitude: null,
        cancelTime: null,
        cancelOperator: null,
        cancelTypeCode: null,
        driveMile: null,
        driveTime: null,
        orderStatus: null,
        price: null,
        gmtCreate: null,
        gmtModified: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单信息2";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改订单信息2";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除订单信息2编号为"' + ids + '"的数据项？').then(function() {
        return delInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('car/info/export', {
        ...this.queryParams
      }, `info_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
